package com.andy.dialog

import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager

//Activity显示Dialog
fun AppCompatActivity.showDialog(commonDialog: CommonDialog.() -> Unit): CommonDialog {
    val dialog = CommonDialog.init()
    dialog.apply(commonDialog)
    setActivityDialog(this.supportFragmentManager, dialog)
    return dialog
}

//Fragment显示Dialog
fun Fragment.showDialog(commonDialog: CommonDialog.() -> Unit): CommonDialog {
    val dialog = CommonDialog.init()
    dialog.apply(commonDialog)
    setActivityDialog(this.childFragmentManager, dialog)
    return dialog
}

private fun setActivityDialog(manger: FragmentManager, dialog: CommonDialog) {
    dialog.showDialog(manger)
}
